package org.dreamwork.jasmine2.events;

import org.dreamwork.jasmine2.web.IWebControl;
import org.dreamwork.jasmine2.web.controls.Page;

import java.util.EventObject;

public class ServerSideEvent extends EventObject {
    private static final String[] TYPES = {
        "onchanged", "onclicked", "ondblclicked", "oncontextmenu"
    };

    public static final String TYPE_ON_CHANGED = TYPES [0];
    public static final String TYPE_ON_CLICKED = TYPES [1];
    public static final String TYPE_ON_DOUBLE_CLICKED = TYPES [2];
    public static final String TYPE_ON_CONTEXT_MENU = TYPES [3];

    private IWebControl m_control;
    private Page m_page;

    public ServerSideEvent (Page page) {
        super (page);
        m_page = page;
    }

    public ServerSideEvent (IWebControl control, Page page) {
        super (control);
        m_control = control;
        m_page = page;
    }

    public IWebControl getControl () {
        return m_control;
    }

    public Page getPage () {
        return m_page;
    }

    public static boolean isLegalType (String type) {
        if (type == null) return false;
        for (int i = 0; i < TYPES.length; i ++) {
            if (type.equals (TYPES [i])) return true;
        }

        return false;
    }
}